package ServerPackge;

/**
 * Http 协议工具，提供响应头信息，提供200和404返回信息
 */
public class HttpProtocolUtil {

    /**
     * 为响应码 200 提供请求头信息
     * @param contentLength 内容长度
     * @return
     */
    public static String getHttpHeader200(long contentLength){
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html \n" +
                "Content-length: " + contentLength + "\n" +
                "\r\n";
    }

    /**
     * 为响应码 404 提供请求信息
     * @return
     */
    public static String getHttpHeader404(){
        String str404 = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 NOT FOUND \n" +
                "Content-Type: text/html" +
                "Content-Length: " + str404.getBytes().length + "\n" +
                "\r\n" + str404;
    }

}
